package com.atguigu.xuexiplus.mapper;

import com.atguigu.xuexiplus.entity.HomeworkCompletion;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 作业完成记录Mapper接口
 */
@Mapper
public interface HomeworkCompletionMapper extends BaseMapper<HomeworkCompletion> {
    @Select("SELECT * FROM homework_completion WHERE homework_id = #{homeworkId} AND student_id = #{studentId} LIMIT 1")
    HomeworkCompletion findOne(@Param("homeworkId") Long homeworkId, @Param("studentId") Long studentId);

    @Update("UPDATE homework_completion SET completion_status = #{status}, updated_at = NOW() WHERE homework_id = #{homeworkId} AND student_id = #{studentId}")
    int updateStatus(@Param("homeworkId") Long homeworkId, @Param("studentId") Long studentId, @Param("status") Integer status);
}
